package cn.yunhe.servlet;

import cn.yunhe.entity.Product;
import cn.yunhe.service.ProductService;
import cn.yunhe.util.PageUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/productListServlet")
public class ProductListServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       ProductService productService = new ProductService();
       int curpage =1;
       String curStr= request.getParameter("curpage");
       if(curStr!=null){
           curpage=Integer.parseInt(curStr);
       }
       int procont =  productService.getProCount();

       List<Product> productLists = productService.getAllproBypage(curpage);

       request.setAttribute("pageTotle",PageUtil.getTotalPages(procont));
       request.setAttribute("productLists", productLists);
       request.setAttribute("curpage",curpage);
       request.getRequestDispatcher("manage/product.jsp").forward(request,response);

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
